package com.zhengxiang.onlinexamination.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhengxiang.onlinexamination.dao.QuAnswerMapper;
import com.zhengxiang.onlinexamination.dao.WaitPaperMapper;
import com.zhengxiang.onlinexamination.entity.QuAnswer;
import com.zhengxiang.onlinexamination.entity.WaitPaper;
import com.zhengxiang.onlinexamination.entity.vo.QuAnswerVo;
import com.zhengxiang.onlinexamination.service.QuAnswerService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.*;

/**
 * 题目答案(ZQuAnswer)表服务实现类
 *
 * @author
 * @since 2023-03-09 17:30:04
 */
@Service("quAnswerService")
public class QuAnswerServiceImpl extends ServiceImpl<QuAnswerMapper, QuAnswer> implements QuAnswerService {
    @Resource
    private QuAnswerMapper quAnswerMapper;

@Resource
private WaitPaperMapper waitPaperMapper;

    @Override
    public void calculationScore(QuAnswerVo qat) {
        //总分
        int countScore=0;
        if(CollectionUtil.isNotEmpty(qat.getQuAnswers())){
            //答题题目id
            List<Integer>doneAnswerIds = new ArrayList<>();
            List<Integer>unAnswerIds = new ArrayList<>();
            //分拣已答和未答
            qat.getQuAnswers().forEach(s->{
                if(s.getQuAnswerId()>0){
                    doneAnswerIds.add(s.getQuId());
                }else{
                    unAnswerIds.add(s.getQuId());
                }
            });
            //获取所有正确的题目答案
            WaitPaper waitPaper = waitPaperMapper.selectById(qat.getWaitPaperId());
            JSONObject parse = JSONObject.parseObject(waitPaper.getPaperContent());
            List<Integer> correctQuAnswerId = (List<Integer>)parse.getJSONObject("correctQuAnswerId");
            List<Object> resultList = new ArrayList<>();

            //获取用户提交的答案，去查询所有正确的题目并打分
            QueryWrapper<QuAnswer> qaWrapper = new QueryWrapper<>();
            qaWrapper.lambda().in(QuAnswer::getQuId,doneAnswerIds);
//            quAnswerDao.selectList();
            //错误的统统记0分
            //错误的生成错题记录
        }
    }
}
